<?php

namespace Trawind\Events\Subscribers\Product\Item;

use Trawind\Events\Events\Inventory\Receipt\StoreNoticeRecordEvent;
use Trawind\Events\Events\Product\Item\ItemPurchaseEvent;
use Trawind\Events\Events\Product\Item\UpdateItemEvent;
use Trawind\Remotes\Repositories\Product\Item\SkuRepositoryEloquent;

class SkuSubscriber
{

    const UPDATE_PACKAGE_RATIO = 'update_package_ratio';

    const UPDATE_ITEM = 'update_item';


    public function subscribe($events)
    {
        $events->listen(
            StoreNoticeRecordEvent::class,
            function (StoreNoticeRecordEvent $event) {
                app(SkuRepositoryEloquent::class)
                    ->callback($event->payload['skus'], static::UPDATE_PACKAGE_RATIO);
            }
        );

        $events->listen(
            UpdateItemEvent::class,
            function (UpdateItemEvent $event) {
                app(SkuRepositoryEloquent::class)
                    ->callback($event->payload, static::UPDATE_ITEM);
            }
        );
    }

}